#include "AndNode.h"
#include "..\Common\AssertHelper.h"

using namespace std;

namespace CExpression
{
	void AndNode::Eval(ExecuteContext &context)
	{
		this->left->Eval(context);
		if(AssertHelper::ExpectType(context.TempResultType(),ExecuteRunTimeType::Boolean,context,TEXT("And operator's operand must be bool type.")))
		{
			bool operand1=context.GlobalTempBoolean();
			this->right->Eval(context);
			if(AssertHelper::ExpectType(context.TempResultType(),ExecuteRunTimeType::Boolean,context,TEXT("And operator's operand must be bool type.")))
			{
				context.SetGlobalTempBoolean(operand1&&context.GlobalTempBoolean());
				context.SetTempResultType(ExecuteRunTimeType::Boolean);
			}
		}
	}

	shared_ptr<Node> AndNode::Clone(Expression &parent)
	{
		shared_ptr<Node> result(new AndNode(this->left->Clone(parent),this->right->Clone(parent)));
		return result;
	}
}